// pages/invoiceHis/invoiceHis.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    type: 1
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    //获取手机高度
    that.setData({
      navH: app.globalData.navHeight
    });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    var that = this;
    that.setData({
      nickName : wx.getStorageSync("nickName"),
      level : wx.getStorageSync("level"),
      avatarUrl: wx.getStorageSync("avatar"),
    })
    wx.request({
      url: app.globalData.url + "getUserByMyInviteList",
      header: {
        "content-type": "application/x-www-form-urlencoded"
      },
      data: {
        type: 1,
        userId: wx.getStorageSync("userId")
      },
      method: "POST",
      success: function (res) {
        var data = res.data;
        if (data.result === 1) {
          that.setData({
            task: data.data,
            screening: 1
          })
        }
      },
      complete: function () {
        wx.hideLoading();
      }
    })


    wx.request({
      url: app.globalData.url + "getDirectOrIndirectRecommendList",
      header: {
        "content-type": "application/x-www-form-urlencoded"
      },
      data: {
        type: 0,
        userId: wx.getStorageSync("userId")
      },
      method: "POST",
      success: function (res) {
        that.setData({
          myData:res.data.data
        })
      },
      complete: function () {
        wx.hideLoading();
      }
    })
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  city: function (e) {
    var that = this;
    that.setData({
      type: e.currentTarget.dataset.type
    })
    wx.request({
      url: app.globalData.url + "getDirectOrIndirectRecommendList",
      header: {
        "content-type": "application/x-www-form-urlencoded"
      },
      data: {
        type: e.currentTarget.dataset.type-1,
        userId: wx.getStorageSync("userId")
      },
      method: "POST",
      success: function (res) {
        that.setData({
          myData:res.data.data
        })
      },
      complete: function () {
        wx.hideLoading();
      }
    })
  },
  navBack: function () {
    wx.navigateBack({

    })
  },
  modal_s_code: function (e) {
    var that = this;
    wx.request({
      url: app.globalData.url + "userReceivesGiftBag",
      header: {
        "content-type": "application/x-www-form-urlencoded"
      },
      data: {
        userId: wx.getStorageSync("userId")
      },
      method: "POST",
      success: function (res) {
        if(res.result == 1){
          wx.showToast({
            title: '领取成功',
            icon:"success"
          })
        }else{
          wx.showToast({
            title: res.data.errmsg,
            icon:"none"
          })
        }
      },
      complete: function () {
        wx.hideLoading();
      }
    })
  },
})
